import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gameplay_flutter/lib_baseview/lib_baseview.dart';
import 'package:gameplay_flutter/lib_runtime/extension/string_extension/string_text.dart';
import 'package:gameplay_flutter/m_room/constants/room_assets.dart';
import 'package:ones/ui.dart';
import '../../m_me/constants/me_assets_constants.dart';
import '../model/room_info.dart';
import '../room_controller/room_controller.dart';
import '../room_controller/room_stateless_controller_mixin.dart';

class RoomTop extends StatelessWidget
    with StatelessControllerMixin<RoomController> {
  RoomTop({
    Key? key,
  }) : super(key: key);

  // RoomMainController controller = Get.put(RoomMainController());

  @override
  Widget build(BuildContext context) {
    final controller = getRoomController(context);
    return Container(
      width: 1.sw,
      padding: EdgeInsets.only(top: 9.h),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          _buildRoomAvatarWidget(controller.roomDataModel?.roomInfo),
          const Spacer(),
          Image.asset(RoomAssets.roomShare, width: 32.w, height: 32.h),
          SizedBox(
            width: 12.w,
          ),
          Image.asset(RoomAssets.roomExit, width: 32.w, height: 32.h),
          SizedBox(
            width: 15.w,
          ),
        ],
      ),
    );
  }

  Widget _buildRoomAvatarWidget(RoomInfo? roomInfo) {
    return Container(
        height: 52.h,
        constraints: BoxConstraints(maxWidth: 1.sw * 0.73, minWidth: 1),
        decoration: BoxDecoration(
            color: const Color(0x0DFFFFFF),
            borderRadius: BorderRadiusDirectional.only(
              topEnd: Radius.circular(52.h / 2.0),
              bottomEnd: Radius.circular(52.h / 2.0),
            )),
        padding: EdgeInsetsDirectional.only(start: 15.w, end: 12.w),
        child: IntrinsicWidth(
          child: Row(
              crossAxisAlignment: CrossAxisAlignment.center, // 添加这一行
              children: [
                CircleAvatar(
                  radius: 20.h,
                  backgroundImage:
                      CachedNetworkImageProvider(roomInfo?.icon ?? ''),
                  // 使用 NetworkImage
                  child: roomInfo?.icon == null
                      ? Image.asset(
                          MeAssetsConstants.iconEmpty) // 如果没有图片，显示加载动画
                      : null,
                ).onClick((){

                }),
                SizedBox(
                  width: 8.w,
                ),
                Expanded(
                  child: Padding(
                    padding: EdgeInsets.symmetric(vertical: 6.h),
                    child: Column(
                      mainAxisSize: MainAxisSize.max,
                      // 占用父组件最大高度
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      // 内容撑满垂直空间
                      crossAxisAlignment: CrossAxisAlignment.start,
                      // 左对齐
                      children: [
                        Flexible(
                          child: (roomInfo?.name ?? "Name Na").text(
                            fontSize: 16.sp,
                            color: Colors.white,
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                            weight: TextFontWeight.medium,
                          ),
                        ),
                        Flexible(
                          child:
                              ("ID:${roomInfo?.roomCode ?? "00000000"}").text(
                            fontSize: 14.sp,
                            color: const Color(0xFFFFFFFF),
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                            weight: TextFontWeight.medium,
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
                SizedBox(
                  width: 8.w,
                ),
                Image.asset(RoomAssets.roomFollow, width: 26.w, height: 26.h)
              ]),
        ));
  }


}
